﻿Public Class HoaDonDAO

    Public Shared Function HoaDon_Load() As DataTable
        Return DataProvider.LoadTable("Select * from HoaDon")
    End Function

    Public Shared Sub HoaDon_Insert(ByVal h As HoaDonDTO)
        Dim Npara As Integer = 4
        Dim sql As String = "usp_HOADON_InsertHOADON"
        Dim name As String() = New String(Npara - 1) {}
        Dim value As Object() = New Object(Npara - 1) {}
        name(0) = "@MAHOADON"
        name(1) = "@MAKH"
        name(2) = "@NGAYLAP"
        name(3) = "@TONGTIEN"
        h.Mahoadon = AutoInc.AutoIncStr(HoaDonDAO.HoaDon_Load, "MAHOADON", "HD")
        value(0) = h.Mahoadon
        value(1) = h.Makh
        value(2) = h.Ngaylap
        value(3) = h.Tongtien
        DataProvider.ExecuteNonQueryPara(sql, name, value, Npara)
    End Sub

    Public Shared Sub HoaDon_Update(ByVal h As HoaDonDTO)
        Dim Npara As Integer = 4
        Dim sql As String = "usp_HOADON_UpdateHOADON"
        Dim name As String() = New String(Npara - 1) {}
        Dim value As Object() = New Object(Npara - 1) {}
        name(0) = "@MAHOADON"
        name(1) = "@MAKH"
        name(2) = "@NGAYLAP"
        name(3) = "@TONGTIEN"
        value(0) = h.Mahoadon
        value(1) = h.Makh
        value(2) = h.Ngaylap
        value(3) = h.Tongtien
        DataProvider.ExecuteNonQueryPara(sql, name, value, Npara)
    End Sub
    Public Shared Sub HoaDon_Delete(ByVal h As HoaDonDTO)
        Dim sql As String = String.Format("delete HoaDon where MAHoaDon = '{0}'", h.Mahoadon)
        DataProvider.ExecuteNonQuery(sql)
    End Sub
End Class
